Skip to content

feat(filesystem): add head/tail support to read_multiple_files#4025

Open
factspark23-hash wants to merge 1 commit intomodelcontextprotocol:mainfrom
factspark23-hash:feat/read-multiple-head-tail
Open

feat(filesystem): add head/tail support to read_multiple_files#4025
factspark23-hash wants to merge 1 commit intomodelcontextprotocol:mainfrom
factspark23-hash:feat/read-multiple-head-tail

Conversation

@factspark23-hash
Copy link
Copy Markdown

What

Add optional head and tail parameters to the read_multiple_files tool, allowing line-limited reads across multiple files at once.

Why

The single-file read_text_file already supports head and tail, but read_multiple_files does not. When working with multiple large files (logs, configs, data files), agents often only need the first/last N lines of each.

Currently the only option is to call read_text_file with head/tail N times, which is slower and more verbose.

How

read_multiple_files({
  paths: ["log1.txt", "log2.txt", "log3.txt"],
  tail: 20  // last 20 lines of each file
})
  • head — returns only the first N lines of each file
  • tail — returns only the last N lines of each file
  • Cannot use both simultaneously (throws error, same as read_text_file)
  • Omitting both reads full files (backward compatible)

Changes

  • src/filesystem/index.ts:
    • Added head and tail to ReadMultipleFilesArgsSchema
    • Updated handler to use headFile/tailFile from lib.ts
    • Updated tool description
    • Added mutual exclusion check (same pattern as read_text_file)

Add per-file head/tail line limits when reading multiple files.
- head: returns only the first N lines of each file
- tail: returns only the last N lines of each file
- Cannot use both simultaneously (throws error)
- Backward compatible: omitting both reads full files

Useful for previewing large log files, checking file headers,
or sampling content from many files at once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant